# Find ILMBASE toolkit
# This module defines
# ILMBASE_FOUND
# ILMBASE_INCLUDE_DIR
# ILMBASE_LIBRARIES
#

FIND_PATH(ILMBASE_INCLUDE_DIR OpenEXR/half.h
    ${ILMBASE_PACKAGE_PREFIX}/include
)

# Half - Debug version
MACRO(FIND_HALF_LIBRARY_DEBUG MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_HALF_LIBRARY_DEBUG LIBRARY LIBRARYNAME)

# Half - Release version
MACRO(FIND_HALF_LIBRARY MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_HALF_LIBRARY LIBRARY LIBRARYNAME)

# Iex - Debug version
MACRO(FIND_IEX_LIBRARY_DEBUG MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_IEX_LIBRARY_DEBUG LIBRARY LIBRARYNAME)

# Iex - Release version
MACRO(FIND_IEX_LIBRARY MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_IEX_LIBRARY LIBRARY LIBRARYNAME)

# Imath - Debug version
MACRO(FIND_IMATH_LIBRARY_DEBUG MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_IMATH_LIBRARY_DEBUG LIBRARY LIBRARYNAME)

# Imath - Release version
MACRO(FIND_IMATH_LIBRARY MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_IMATH_LIBRARY LIBRARY LIBRARYNAME)

# IlmThread - Debug version
MACRO(FIND_ILMTHREAD_LIBRARY_DEBUG MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_ILMTHREAD_LIBRARY_DEBUG LIBRARY LIBRARYNAME)

# IlmThread - Release version
MACRO(FIND_ILMTHREAD_LIBRARY MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATHS
        ${ILMBASE_PACKAGE_PREFIX}/lib
    )
ENDMACRO(FIND_ILMTHREAD_LIBRARY LIBRARY LIBRARYNAME)

FIND_HALF_LIBRARY_DEBUG(HALF_LIBRARY_DEBUG Halfd)
FIND_HALF_LIBRARY(HALF_LIBRARY Half)

FIND_IEX_LIBRARY_DEBUG(IEX_LIBRARY_DEBUG Iex-2_1d)
FIND_IEX_LIBRARY(IEX_LIBRARY Iex-2_1)

FIND_IMATH_LIBRARY_DEBUG(IMATH_LIBRARY_DEBUG Imath-2_1d)
FIND_IMATH_LIBRARY(IMATH_LIBRARY Imath-2_1)

FIND_ILMTHREAD_LIBRARY_DEBUG(ILMTHREAD_LIBRARY_DEBUG IlmThread-2_1d)
FIND_ILMTHREAD_LIBRARY(ILMTHREAD_LIBRARY IlmThread-2_1)

IF(HALF_LIBRARY)
  IF(HALF_LIBRARY_DEBUG)
    SET(HALF_LIBRARIES optimized "${HALF_LIBRARY}" debug "${HALF_LIBRARY_DEBUG}")
  ELSE()
    SET(HALF_LIBRARIES "${HALF_LIBRARY}")
  ENDIF()
ENDIF()

IF(IEX_LIBRARY)
  IF(IEX_LIBRARY_DEBUG)
    SET(IEX_LIBRARIES optimized "${IEX_LIBRARY}" debug "${IEX_LIBRARY_DEBUG}")
  ELSE()
    SET(IEX_LIBRARIES "${IEX_LIBRARY}")
  ENDIF()
ENDIF()

IF(IMATH_LIBRARY)
  IF(IMATH_LIBRARY_DEBUG)
    SET(IMATH_LIBRARIES optimized "${IMATH_LIBRARY}" debug "${IMATH_LIBRARY_DEBUG}")
  ELSE()
    SET(IMATH_LIBRARIES "${IMATH_LIBRARY}")
  ENDIF()
ENDIF()

IF(ILMTHREAD_LIBRARY)
  IF(ILMTHREAD_LIBRARY_DEBUG)
    SET(ILMTHREAD_LIBRARIES optimized "${ILMTHREAD_LIBRARY}" debug "${ILMTHREAD_LIBRARY_DEBUG}")
  ELSE()
    SET(ILMTHREAD_LIBRARIES "${ILMTHREAD_LIBRARY}")
  ENDIF()
ENDIF()

SET(ILMBASE_FOUND "NO")
IF(HALF_LIBRARIES AND IEX_LIBRARIES AND IMATH_LIBRARIES AND ILMTHREAD_LIBRARIES AND ILMBASE_INCLUDE_DIR)
  SET(ILMBASE_LIBRARIES ${HALF_LIBRARIES} ${IEX_LIBRARIES} ${IMATH_LIBRARIES} ${ILMTHREAD_LIBRARIES})
  SET(ILMBASE_FOUND "YES")
  MESSAGE( STATUS "IlmBase - Found" )
ENDIF(HALF_LIBRARIES AND IEX_LIBRARIES AND IMATH_LIBRARIES AND ILMTHREAD_LIBRARIES AND ILMBASE_INCLUDE_DIR)
